<?php
namespace app\api_wp_v01\controller;

class StaffMine extends Staff {
	
	public function get_info() {
		
		return $this->disposeJson(0, '', array(
			'realname' => $this->staff_info['realname'],
			'phone' => $this->staff_info['phone'],
		));
	}
	
	public function edit_info() {
		
		$parameter = \think\Request::instance()->post();
		$judge_1 = array_key_exists('realname', $parameter) && is_string($parameter['realname']) && (0 < mb_strlen($parameter['realname'], 'utf8')) && (11 > mb_strlen($parameter['realname'], 'utf8'));
		$judge_2 = array_key_exists('phone', $parameter) && is_string($parameter['phone']) && (1 == preg_match('/^[0-9]{11}$/', $parameter['phone']));
		if(!$judge_1 || !$judge_2){
			return $this->disposeJson(1, '参数校验失败');
		};
		
		$result = \app\common\model\StaffModel::where('id', $this->staff_id)->update([
			'realname' => $parameter['realname'],
			'phone' => $parameter['phone'],
		]);
		if(false == $result){
			return $this->disposeJson(0, '修改成功');
		};
		
		return $this->disposeJson(0, '修改成功');
	}
	
}